home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCTAGS15.ARJ / SORT.DIF < prev    next >
Text File  |  1991-10-02  |  6KB  |  260 lines

  1. *** tmp\sort.c    Sun Aug 26 23:19:34 1990
  2. --- sort.c    Wed Oct 02 20:13:38 1991
  3. ***************
  4. *** 30,39 ****
  5. --- 30,44 ----
  6.   static char version[] = "GNU sort, version 0.3";
  7.   
  8.   #include "std.h"
  9.   #ifndef MSDOS
  10.   #include "unix.h"
  11.   #endif /* not MSDOS */
  12.   
  13. + #ifdef SORT_MODULE
  14. + #include "sort.h"
  15. + #endif
  16.   #include <errno.h>
  17.   #include <signal.h>
  18.   #include <stdio.h>
  19. ***************
  20. *** 72,78 ****
  21. --- 77,85 ----
  22.   static void usage (void);
  23.   static void badfieldspec (char *s);
  24.   static void inthandler (void);
  25. + #ifndef SORT_MODULE
  26.   int main (int argc, char **argv);
  27. + #endif
  28.   #endif /* MSDOS */
  29.   
  30.   /* A few useful macros. */
  31. ***************
  32. *** 187,192 ****
  33. --- 194,202 ----
  34.                  "      the MS-DOS version.  For files with short lines, use\n"
  35.                  "      the `-S <num>' option to reduce the buffer size.\n");
  36.         cleanup ();
  37. + #ifdef SORT_MODULE
  38. +       external_cleanup();
  39. + #endif
  40.         exit (-1);
  41.       }
  42.   }
  43. ***************
  44. *** 239,244 ****
  45. --- 249,258 ----
  46.   {
  47.     struct tempnode *node;
  48.   
  49. + #ifdef MSDOS
  50. +   fcloseall();
  51. + #endif
  52. +     
  53.     for (node = temphead.next; node; node = node->next)
  54.       remove(node->name);
  55.   }
  56. ***************
  57. *** 255,260 ****
  58. --- 269,277 ----
  59.       return r;
  60.     fprintf (stderr, "sort: memory exausted\n");
  61.     cleanup ();
  62. + #ifdef SORT_MODULE
  63. +   external_cleanup();
  64. + #endif
  65.     exit (-1);
  66.   }
  67.   
  68. ***************
  69. *** 267,272 ****
  70. --- 284,292 ----
  71.       return r;
  72.     fprintf (stderr, "sort: memory exhausted\n");
  73.     cleanup ();
  74. + #ifdef SORT_MODULE
  75. +   external_cleanup();
  76. + #endif
  77.     exit (-1);
  78.   }
  79.   
  80. ***************
  81. *** 282,287 ****
  82. --- 302,310 ----
  83.       return r;
  84.     fprintf(stderr, "sort: memory exausted\n");
  85.     cleanup();
  86. + #ifdef SORT_MODULE
  87. +   external_cleanup();
  88. + #endif
  89.     exit(-1);
  90.   }
  91.   
  92. ***************
  93. *** 296,301 ****
  94. --- 319,327 ----
  95.       return r;
  96.     fprintf(stderr, "sort: memory exhausted\n");
  97.     cleanup();
  98. + #ifdef SORT_MODULE
  99. +   external_cleanup();
  100. + #endif
  101.     exit(-1);
  102.   }
  103.   
  104. ***************
  105. *** 312,317 ****
  106. --- 338,346 ----
  107.     fprintf(stderr, "sort: cannot open %s (%s): %s\n", file, how,
  108.             strerror(errno));
  109.     cleanup();
  110. + #ifdef SORT_MODULE
  111. +   external_cleanup();
  112. + #endif
  113.     exit(-1);
  114.   }
  115.   
  116. ***************
  117. *** 325,330 ****
  118. --- 354,362 ----
  119.         {
  120.           fprintf(stderr, "sort: error in fclose: %s\n", strerror(errno));
  121.           cleanup();
  122. + #ifdef SORT_MODULE
  123. +         external_cleanup();
  124. + #endif
  125.           exit(-1);
  126.         }
  127.   }
  128. ***************
  129. *** 335,344 ****
  130. --- 367,383 ----
  131.        int size, nelem;
  132.        FILE *fp;
  133.   {
  134. + #ifdef MSDOS
  135. +   if (fwrite(buf, size, nelem, fp) < (unsigned) nelem)
  136. + #else /* not MSDOS */
  137.     if (fwrite(buf, size, nelem, fp) < 0)
  138. + #endif /* not MSDOS */
  139.       {
  140.         fprintf(stderr, "sort: error in fwrite: %s\n", strerror(errno));
  141.         cleanup();
  142. + #ifdef SORT_MODULE
  143. +       external_cleanup();
  144. + #endif
  145.         exit(-1);
  146.       }
  147.   }
  148. ***************
  149. *** 354,360 ****
  150.       (struct tempnode *) xmalloc(sizeof (struct tempnode));
  151.   
  152.   #ifdef MSDOS
  153. !   if (len && prefix[len - 1] != '/')
  154.       sprintf(name, "%s/sort%4.4x.%3.3x", prefix, getpid(), ++seq);
  155.     else
  156.       sprintf(name, "%ssort%4.4x.%3.3x", prefix, getpid(), ++seq);
  157. --- 393,399 ----
  158.       (struct tempnode *) xmalloc(sizeof (struct tempnode));
  159.   
  160.   #ifdef MSDOS
  161. !   if (len && prefix[len - 1] != '/' && prefix[len - 1] != '\\')
  162.       sprintf(name, "%s/sort%4.4x.%3.3x", prefix, getpid(), ++seq);
  163.     else
  164.       sprintf(name, "%ssort%4.4x.%3.3x", prefix, getpid(), ++seq);
  165. ***************
  166. *** 448,453 ****
  167. --- 487,495 ----
  168.                      "sort: lines longer than 32k are not supported under\n"
  169.                      "      MS-DOS because of performance considerations.\n");
  170.             cleanup ();
  171. + #ifdef SORT_MODULE
  172. +           external_cleanup();
  173. + #endif
  174.             exit (-1);
  175.           }
  176.   #else /* not MSDOS */
  177. ***************
  178. *** 458,463 ****
  179. --- 500,508 ----
  180.           {
  181.             fprintf(stderr, "sort: read error (%s)\n", strerror(errno));
  182.             cleanup();
  183. + #ifdef SORT_MODULE
  184. +           external_cleanup();
  185. + #endif
  186.             exit(-1);
  187.           }
  188.         buf->used += cc;
  189. ***************
  190. *** 473,478 ****
  191. --- 518,526 ----
  192.                      "sort: lines longer than 32k are not supported under\n"
  193.                      "      MS-DOS because of performance considerations.\n");
  194.             cleanup ();
  195. + #ifdef SORT_MODULE
  196. +           external_cleanup();
  197. + #endif
  198.             exit (-1);
  199.           }
  200.   #else /* not MSDOS */
  201. ***************
  202. *** 1122,1127 ****
  203. --- 1170,1177 ----
  204.             saved.length = lines[ord[0]].lines[cur[ord[0]]].length;
  205.             memcpy(saved.text, lines[ord[0]].lines[cur[ord[0]]].text,
  206.                    saved.length + 1);
  207. +           saved.keybeg = lines[ord[0]].lines[cur[ord[0]]].keybeg;
  208. +           saved.keylim = lines[ord[0]].lines[cur[ord[0]]].keylim;
  209.             savedflag = 1;
  210.           }
  211.         else
  212. ***************
  213. *** 1405,1410 ****
  214. --- 1455,1463 ----
  215.   {
  216.     signal(SIGINT, SIG_DFL);
  217.     cleanup();
  218. + #ifdef SORT_MODULE
  219. +   external_cleanup();
  220. + #endif
  221.   #ifdef MSDOS
  222.     abort ();
  223.   #else /* not MSDOS */
  224. ***************
  225. *** 1423,1429 ****
  226. --- 1476,1486 ----
  227.   #endif /* not MSDOS */
  228.   
  229.   int
  230. + #ifdef SORT_MODULE
  231. + sort_main(argc, argv)
  232. + #else
  233.   main(argc, argv)
  234. + #endif
  235.        int argc;
  236.        char *argv[];
  237.   {
  238. ***************
  239. *** 1753,1758 ****
  240. --- 1810,1826 ----
  241.       merge(files, nfiles, ofp);
  242.     else
  243.       sort(files, nfiles, ofp);
  244. +   /* close the file */
  245. +   if (ofp != stdout)
  246. +     fclose(ofp);
  247.     cleanup();
  248. + #ifdef SORT_MODULE
  249. +   return(0);
  250. + #else /* not SORT_MODULE */
  251.     exit(0);
  252. + #endif /* not SORT_MODULE */
  253.   }
  254.